import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:dio/dio.dart';
import 'dart:async';

class DioPage extends StatelessWidget {
  final SystemUiOverlayStyle _style =
      SystemUiOverlayStyle(statusBarColor: Colors.transparent);

  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(_style);
    // TODO: implement build
    return MaterialApp(
      home: DioStatefulWidget(),
      theme: ThemeData(primarySwatch: Colors.yellow),
    );
  }
}

class DioStatefulWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _DioState();
  }
}

class _DioState extends State<StatefulWidget> {
  String _responseData = "";
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("Dio Page"),
      ),
      body: Column(
          children: <Widget>[
            OutlineButton(
                child: Text("Http"
                ),
                onPressed: () async {
                  debugPrint("exc http request.");
                  Dio dio = Dio();
                  Response response = await dio.get("https://www.baidu.com/");
                  debugPrint("Dio 执行结果: " + response.data);
                  setState(() {
                    _responseData = response.data;
                  });
                }
            ),
            Text("$_responseData")
          ],
            ),

    );
  }
}
